package ro.gateway.aida.obj.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Comparator;
import java.util.StringTokenizer;

import ro.gateway.aida.db.DBPersistenceManager;
import ro.gateway.aida.db.PersistenceToken;
import ro.gateway.aida.obj.searchrows.ActivityRow;
import ro.gateway.aida.utils.SortedList;

/**
 * SearchDB Class performing advanced/standard search
 * 
 * @author Mihai Postelnicu
 *         <p>
 *         mihai@ro-gateway.org
 */
public class SearchDB extends DBPersistenceManager {
	private String searchLang = "en";
	private String country_iso3 = null;
	private String sectors = null;
	private String title = null;
	private String description = null;
	private int fundingOrg = -1;
	private int status = -1;
	private String projectID = null;
	private int donorOrg = -1;
	private int contractingOrg = -1;
	private int beneficiaryOrg = -1;
	private int involvedPerson = -1;
	private int infoSourceOrg = -1;
	/**
	 * @return Returns the infoSourceOrg.
	 */
	public int getInfoSourceOrg() {
		return infoSourceOrg;
	}
	/**
	 * @param infoSourceOrg The infoSourceOrg to set.
	 */
	public void setInfoSourceOrg(int infoSourceOrg) {
		this.infoSourceOrg = infoSourceOrg;
	}
	private String keywords = null;
	private long userID = -1;
	private boolean sortByTitle = true;
	private boolean attachLocations = false;
	private boolean attachSectors = false;
	private boolean hideUnapproved = false;
	private boolean cumulative = false; //if this is true, searched items will
										// be linked by OR

	//location info
	private String loc_countryiso3 = null;
	private int loc_regionId = -1;
	private int loc_countyId = -1;
	private int loc_townId = -1;
	private int loc_villageId = -1;
	private int loc_cregionId = -1;

	private SearchDB(PersistenceToken token) {
		super(token);
	}

	public static SearchDB getManager(PersistenceToken token) {
		return new SearchDB(token);
	}

	public SortedList reorder(String by, SortedList l) {

		if ("country".equals(by))
			l.setComparator(new CountryComparator());

		if ("sector".equals(by))
			l.setComparator(new SectorComparator());

		if ("title".equals(by))
			l.setComparator(new TitleComparator());

		if ("date".equals(by))
			l.setComparator(new DateComparator());

		return l;
	}

	public String getSectors() {
		return sectors;
	}

	public void setSectors(String sectors) {
		this.sectors = sectors;
	}

	public int getFundingOrg() {
		return fundingOrg;
	}

	public void setFundingOrg(int fundingOrg) {
		this.fundingOrg = fundingOrg;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getProjectID() {
		return projectID;
	}

	public void setProjectID(String projectID) {
		this.projectID = projectID;
	}

	/**
	 * Creates the search query in the stringbuffer. Concatenates different
	 * parts of the query.
	 * 
	 * @param query
	 *            the start of the query
	 * @param portion
	 *            the concatenated part
	 * @param no
	 *            an external counter
	 */
	private void queryAppend(StringBuffer query, String portion, int no) {
		if (no == 0)
			query.append("WHERE");
		else if (cumulative)
			query.append("OR");
		else
			query.append("AND");

		query.append(portion);
	}

	
	/**
	 * Performs advanced search based on bean info
	 * @deprecated
	 * @return a
	 */
	
	public SortedList advancedSearch() throws SQLException {
		int qno = 0;
		StringBuffer sb = new StringBuffer("select id from activities ");
		StringBuffer keystr = new StringBuffer();

		//if (title != null)
//			title = title.toUpperCase();

		if (keywords != null) {
			StringTokenizer st = new StringTokenizer(keywords, ",");

			while (st.hasMoreTokens()) {
				keystr.append("g.name ilike ('%");
				keystr.append(st.nextToken().trim());
				keystr.append("%') OR ");
			}

			keystr.delete(keystr.length() - 4, keystr.length() - 1);
		}

		String COUNTRY_FILTER = " id in (select o.activity_id from "
				+ " objects o,locations l where o.id=l.id and l.country_iso3='"
				+ country_iso3 + "') ";
		String SECTOR_FILTER = " id in (select o.activity_id from "
				+ " objects o,sectors s where o.id=s.id and (s.ro_aida_code in ("
				+ sectors + ") OR s.ro_aida_code in ( SELECT ro_aida_code FROM " +
						"ro_aida_sectors WHERE parent_ro_aida_code= " +sectors + " )))";
		String TITLE_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_titles g where o.id=g.id and g.name ILIKE ('%"
				+ title + "%')) ";
		String KEYWORDS_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_keywords g where o.id=g.id and ("
				+ keystr.toString() + ")) ";
		String TEXT_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_descriptions gd,gen_objectives go,gen_results gr where "
				+ "o.id=gd.id and o.id=go.id and o.id=gr.id and (go.name ILIKE('"
				+ description + "') or gd.name ILIKE ('" + description
				+ "') or gr.name ilike ('" + description + "'))) ";
		String STATUS_FILTER = " harm_status = " + status;

		if (status == 0)
			STATUS_FILTER = " harm_status IS NULL ";

		String DONOR_ID_FILTER = " id in (select activity_id from "
				+ " donor_ids where donor_id ILIKE (" + projectID + ")) ";
		String DONOR_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=102 and oi.org_id="
				+ donorOrg
				+ ") ";
		String FUNDING_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=1 and oi.org_id="
				+ fundingOrg + ") ";
		String CONTRACTING_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=101 and oi.org_id="
				+ contractingOrg + ") ";
		String BENEFICIARY_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=100 and oi.org_id="
				+ beneficiaryOrg + ") ";
		String INVOLVED_PERSON_FILTER = " id in (select o.activity_id from objects o, pers_inv pi"
				+ " where o.id=pi.id and pi.pers_id=" + involvedPerson + ") ";
		String USER_ID_FILTER = " id in (select o.activity_id from objects o where o.user_id="
				+ userID + ") ";

		String APPROVED_FILTER = " id in (select a.id from activities a where a.approved='Y') ";

		if (status != -1)
			queryAppend(sb, STATUS_FILTER, qno++);

		if (sectors != null)
			queryAppend(sb, SECTOR_FILTER, qno++);

		if (userID != -1)
			queryAppend(sb, USER_ID_FILTER, qno++);

		if (projectID != null)
			queryAppend(sb, DONOR_ID_FILTER, qno++);

		if (donorOrg != -1)
			queryAppend(sb, DONOR_ORG_FILTER, qno++);

		if (fundingOrg != -1)
			queryAppend(sb, FUNDING_ORG_FILTER, qno++);

		if (contractingOrg != -1)
			queryAppend(sb, CONTRACTING_ORG_FILTER, qno++);

		if (involvedPerson != -1)
			queryAppend(sb, INVOLVED_PERSON_FILTER, qno++);

		if (keywords != null)
			queryAppend(sb, KEYWORDS_FILTER, qno++);

		if (title != null)
			queryAppend(sb, TITLE_FILTER, qno++);

		if (description != null)
			queryAppend(sb, TEXT_FILTER, qno++);

		if (country_iso3 != null)
			queryAppend(sb, COUNTRY_FILTER, qno++);

		if (hideUnapproved)
			queryAppend(sb, APPROVED_FILTER, qno++);

		return performSearch(sb.toString());
	}

	
	public String createSearchQuery() throws SQLException {
		int qno = 0;
		StringBuffer sb = new StringBuffer("select id from activities ");
		StringBuffer keystr = new StringBuffer();

		//if (title != null)
//			title = title.toUpperCase();

		if (keywords != null) {
			StringTokenizer st = new StringTokenizer(keywords, ",");
			
			while (st.hasMoreTokens()) {
				keystr.append("g.name ILIKE ('%");
				keystr.append(st.nextToken().trim());
				keystr.append("%') OR ");
			}

			keystr.delete(keystr.length() - 4, keystr.length() - 1);
		}

		String COUNTRY_FILTER = " id in (select o.activity_id from "
				+ " objects o,locations l where o.id=l.id and l.country_iso3='"
				+ country_iso3 + "') ";
		String SECTOR_FILTER = " id in (select o.activity_id from "
			+ " objects o,sectors s where o.id=s.id and ( s.ro_aida_code in ("
			+ sectors + ") OR s.ro_aida_code IN (SELECT s1.ro_aida_code FROM ro_aida_sectors s1 WHERE s1.parent_ro_aida_code " +
					"IN (SELECT s2.ro_aida_code FROM ro_aida_sectors s2 WHERE s2.parent_ro_aida_code= "+ sectors +")) OR s.ro_aida_code in ( SELECT ro_aida_code FROM " +
					"ro_aida_sectors WHERE parent_ro_aida_code= " +sectors + " )))";
		String TITLE_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_titles g where o.id=g.id and g.name ILIKE ('%"
				+ title + "%')) ";
		String KEYWORDS_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_keywords g where o.id=g.id and ("
				+ keystr.toString() + ")) ";
		String TEXT_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_descriptions gd,gen_objectives go,gen_results gr where "
				+ "o.id=gd.id and o.id=go.id and o.id=gr.id and (go.name ILIKE('"
				+ description + "') or gd.name ILIKE ('" + description
				+ "') or gr.name ilike ('" + description + "'))) ";
		String STATUS_FILTER = " harm_status = " + status;

		if (status == 0)
			STATUS_FILTER = " harm_status IS NULL ";

		String DONOR_ID_FILTER = " id in (select activity_id from "
				+ " donor_ids where donor_id ilike (" + projectID + ")) ";
		String DONOR_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=102 and oi.org_id="
				+ donorOrg
				+ ") ";
		String FUNDING_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=1 and oi.org_id="
				+ fundingOrg + ") ";
		String INFO_SOURCE_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
			+ " where o.id=oi.id and oi.role=103 and oi.org_id="
			+ infoSourceOrg + ") ";
		String CONTRACTING_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=101 and oi.org_id="
				+ contractingOrg + ") ";
		String BENEFICIARY_ORG_FILTER = " id in (select o.activity_id from objects o, orgs_inv oi"
				+ " where o.id=oi.id and oi.role=100 and oi.org_id="
				+ beneficiaryOrg + ") ";
		String INVOLVED_PERSON_FILTER = " id in (select o.activity_id from objects o, pers_inv pi"
				+ " where o.id=pi.id and pi.pers_id=" + involvedPerson + ") ";
		String USER_ID_FILTER = " id in (select o.activity_id from objects o where o.user_id="
				+ userID + ") ";

		String APPROVED_FILTER = " id in (select a.id from activities a where a.approved='Y') ";

		String LOCATION_FILTER = " id in (select o.activity_id from objects o, locations l "
				+ " WHERE o.id=l.id AND o.obj_type=23 "
				+ (this.loc_cregionId != -1 ? " AND l.cregion_id="
						+ this.loc_cregionId : "")
				+ (this.loc_countryiso3 != null ? " AND l.country_iso3='"
						+ this.loc_countryiso3 +"'": "")
				+ (this.loc_regionId != -1 ? " AND l.reg_id="
						+ this.loc_regionId : "")
				+ (this.loc_countyId != -1 ? " AND l.jud_id="
						+ this.loc_countyId : "")
				+ (this.loc_townId != -1 ? " AND l.sirsup_id="
						+ this.loc_countyId : "")
				+ (this.loc_villageId != -1 ? " AND l.siruta_id="
						+ this.loc_villageId : "")+ " )";

		if (status != -1)
			queryAppend(sb, STATUS_FILTER, qno++);

		if (sectors != null)
			queryAppend(sb, SECTOR_FILTER, qno++);

		if (userID != -1)
			queryAppend(sb, USER_ID_FILTER, qno++);

		if (projectID != null)
			queryAppend(sb, DONOR_ID_FILTER, qno++);

		if (donorOrg != -1)
			queryAppend(sb, DONOR_ORG_FILTER, qno++);

		if (fundingOrg != -1)
			queryAppend(sb, FUNDING_ORG_FILTER, qno++);

		if (infoSourceOrg != -1)
			queryAppend(sb, INFO_SOURCE_ORG_FILTER, qno++);

		
		if (contractingOrg != -1)
			queryAppend(sb, CONTRACTING_ORG_FILTER, qno++);

		if (involvedPerson != -1)
			queryAppend(sb, INVOLVED_PERSON_FILTER, qno++);

		if (keywords != null)
			queryAppend(sb, KEYWORDS_FILTER, qno++);

		if (title != null)
			queryAppend(sb, TITLE_FILTER, qno++);

		if (description != null)
			queryAppend(sb, TEXT_FILTER, qno++);

		if (country_iso3 != null)
			queryAppend(sb, COUNTRY_FILTER, qno++);

		if (hideUnapproved)
			queryAppend(sb, APPROVED_FILTER, qno++);

		if (getLoc_countryiso3() != null || getLoc_countyId() != -1
				|| getLoc_regionId() != -1 || getLoc_townId() != -1
				|| getLoc_cregionId() != -1 || getLoc_villageId() != -1) {
			queryAppend(sb, LOCATION_FILTER, qno++);
		}

		return sb.toString();
	}

	public SortedList simpleSearch() throws SQLException {
		int qno = 0;
		StringBuffer sb = new StringBuffer("select id from activities ");
		StringBuffer keystr = new StringBuffer();

		//if (title != null)
//			title = title.toUpperCase();

		if (keywords != null) {
			StringTokenizer st = new StringTokenizer(keywords,
					",");

			while (st.hasMoreTokens()) {
				keystr.append("g.name ILIKE ('%");
				keystr.append(st.nextToken().trim());
				keystr.append("%') OR ");
			}

			keystr.delete(keystr.length() - 4, keystr.length() - 1);
		}

		String KEYWORDS_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_keywords g where o.id=g.id and ("
				+ keystr.toString() + ")) ";

		String TITLE_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_titles g where o.id=g.id and ("
				+ keystr.toString() + ")) ";

		String DESC_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_descriptions g where o.id=g.id and ("
				+ keystr.toString() + ")) ";

		String OBJ_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_objectives g where o.id=g.id and ("
				+ keystr.toString() + ")) ";

		String RESULTS_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_results g where o.id=g.id and ("
				+ keystr.toString() + ")) ";

		String COMP_FILTER = " id in (select o.activity_id from "
				+ " objects o,gen_components g where o.id=g.id and ("
				+ keystr.toString() + ")) ";

		if (keywords != null) {
			queryAppend(sb, KEYWORDS_FILTER, qno++);
			queryAppend(sb, DESC_FILTER, qno++);
			queryAppend(sb, TITLE_FILTER, qno++);
			queryAppend(sb, OBJ_FILTER, qno++);
			queryAppend(sb, RESULTS_FILTER, qno++);
			queryAppend(sb, COMP_FILTER, qno++);
		}

		return performSearch(sb.toString());
	}

	private SortedList performSearch(String QUERY) throws SQLException {
		Connection con = getConnection();
		SortedList res;
		if (sortByTitle)
			res = new SortedList(new SearchDB.TitleComparator());
		else
			res = new SortedList(new SearchDB.CountryComparator());

		try {
			PreparedStatement ps = con.prepareStatement(FETCH_SEARCH_RESULTS
					+ QUERY + ")");
			ps.setString(1, getSearchLang());
			ps.setString(2, getSearchLang());
			ResultSet rs = ps.executeQuery();

			while (rs.next()) {
				ActivityRow ar = new ActivityRow();
				ar.setId(rs.getLong(1));
				ar.setDate(rs.getDate(2));
				ar.setTitle(rs.getString(3));
				ar.setCountry(rs.getString(4));
				ar.setSector(rs.getString(5));
				res.add(ar);
			}

			rs.close();
			ps.close();

		} finally {
			con.close();
		}

		return res;
	}

	public int getDonorOrg() {
		return donorOrg;
	}

	public void setDonorOrg(int donorOrg) {
		this.donorOrg = donorOrg;
	}

	public int getContractingOrg() {
		return contractingOrg;
	}

	public void setContractingOrg(int contractingOrg) {
		this.contractingOrg = contractingOrg;
	}

	public int getBeneficiaryOrg() {
		return beneficiaryOrg;
	}

	public void setBeneficiaryOrg(int beneficiaryOrg) {
		this.beneficiaryOrg = beneficiaryOrg;
	}

	public int getInvolvedPerson() {
		return involvedPerson;
	}

	public void setInvolvedPerson(int involvedPerson) {
		this.involvedPerson = involvedPerson;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public long getUserID() {
		return userID;
	}

	public void setUserID(long userID) {
		this.userID = userID;
	}

	/**
	 * @return
	 */
	public String getCountry_iso3() {
		return country_iso3;
	}

	/**
	 * @param string
	 */
	public void setCountry_iso3(String string) {
		country_iso3 = string;
	}

	/**
	 * @return
	 */
	public boolean isHideUnapproved() {
		return hideUnapproved;
	}

	/**
	 * @param b
	 */
	public void setHideUnapproved(boolean b) {
		hideUnapproved = b;
	}

	/**
	 * @return
	 */
	public boolean isAttachLocations() {
		return attachLocations;
	}

	/**
	 * @param b
	 */
	public void setAttachLocations(boolean b) {
		attachLocations = b;
	}

	/**
	 * @return
	 */
	public boolean isAttachSectors() {
		return attachSectors;
	}

	/**
	 * @param b
	 */
	public void setAttachSectors(boolean b) {
		attachSectors = b;
	}

	/**
	 * @return
	 */
	public boolean isCumulative() {
		return cumulative;
	}

	/**
	 * @param b
	 */
	public void setCumulative(boolean b) {
		cumulative = b;
	}

	class TitleComparator implements Comparator {
		public int compare(Object o1, Object o2) {
			ActivityRow t1 = (ActivityRow) o1;
			ActivityRow t2 = (ActivityRow) o2;

			return (t1.getTitle().toString().toUpperCase().compareTo(t2
					.getTitle().toString().toUpperCase()));
		}
	}

	class SectorComparator implements Comparator {
		public int compare(Object o1, Object o2) {
			ActivityRow t1 = (ActivityRow) o1;
			ActivityRow t2 = (ActivityRow) o2;

			return (t1.getSector().toString().toUpperCase().compareTo(t2
					.getSector().toString().toUpperCase()));
		}
	}

	class DateComparator implements Comparator {
		public int compare(Object o1, Object o2) {
			ActivityRow t1 = (ActivityRow) o1;
			ActivityRow t2 = (ActivityRow) o2;

			return (t1.getDate().compareTo(t2.getDate()));
		}
	}

	class CountryComparator implements Comparator {
		public int compare(Object o1, Object o2) {
			ActivityRow t1 = (ActivityRow) o1;
			ActivityRow t2 = (ActivityRow) o2;

			return (t1.getCountry().toUpperCase().compareTo(t2.getCountry()
					.toUpperCase()));
		}
	}

	//public static final String ACT = "Activity";
	//public static final String TITLE = "Title";

	/*
	 * public static final String FETCH_SEARCH_RESULTS = "SELECT o.activity_id," +
	 * "CASE WHEN (SELECT count(*) FROM objects o3,gen_titles t WHERE
	 * o3.obj_type=12" + " AND o3.id=t.id AND t.lang=? AND
	 * o3.activity_id=o.activity_id)>0 THEN (" + "SELECT t.name FROM objects
	 * o3,gen_titles t WHERE o3.obj_type=12 AND o3.id=t.id" + " AND t.lang=? AND
	 * o3.activity_id=o.activity_id) ELSE (" + "SELECT t.name FROM objects
	 * o3,gen_titles t WHERE o3.obj_type=12 AND o3.id=t.id AND " +
	 * "o3.activity_id=o.activity_id AND rownum=1) END," + "CASE WHEN (SELECT
	 * count(*) FROM objects oo WHERE oo.obj_type=23 AND" + "
	 * oo.activity_id=o.activity_id)> 1 THEN '--multiple--' ELSE (SELECT
	 * cnt.name FROM " + "countries_iso3 cnt, locations l2,objects o2 WHERE
	 * l2.id=o2.id AND cnt.iso3=l2.country_iso3" + " AND
	 * o.activity_id=o2.activity_id AND o2.obj_type=23 AND rownum=1) END, CASE
	 * WHEN " + "(SELECT count(*) FROM objects oo WHERE oo.obj_type=20 AND
	 * oo.activity_id=o.activity_id)>1 " + "THEN '--multiple--' ELSE (SELECT
	 * ss.name FROM ro_aida_sectors ss, sectors s2,objects o2 " + "WHERE
	 * s2.id=o2.id AND ss.lang=? AND ss.ro_aida_code=s2.ro_aida_code AND " +
	 * "o.activity_id=o2.activity_id AND obj_type=20 AND rownum=1) END FROM
	 * objects o WHERE " + "o.obj_type=0 AND o.activity_id in (";
	 */

	public static final String FETCH_SEARCH_RESULTS = "SELECT o.activity_id, o.date_modif, "
			+ " (SELECT DISTINCT lpd_get_prj_title_name(o3.id,?) FROM objects o3 "
			+ "WHERE o3.obj_type=12 AND o3.activity_id=o.activity_id), "
			+ "CASE WHEN (lpd_get_prj_obj_count(23,o.activity_id)> 1) THEN '--multiple--' ELSE (SELECT cnt.name FROM "
			+ "countries_iso3 cnt, locations l2,objects o2 WHERE l2.id=o2.id  AND cnt.iso3=l2.country_iso3"
			+ " AND o.activity_id=o2.activity_id AND o2.obj_type=23) END, CASE WHEN "
			+ "(lpd_get_prj_obj_count(20,o.activity_id)>1) "
			+ "THEN '--multiple--' ELSE (SELECT DISTINCT lpd_get_sector_name(s2.ro_aida_code,?) FROM sectors s2,objects o2 "
			+ "WHERE s2.id=o2.id AND o.activity_id=o2.activity_id AND obj_type=20) END FROM objects o WHERE "
			+ "o.obj_type=0 AND o.activity_id in (";

	/**
	 * @return
	 */
	public String getSearchLang() {
		return searchLang;
	}

	/**
	 * @param string
	 */
	public void setSearchLang(String string) {
		searchLang = string;
	}

	/**
	 * @return Returns the orderByTitle.
	 */
	public boolean isSortByTitle() {
		return sortByTitle;
	}
	/**
	 * @param orderByTitle
	 *            The orderByTitle to set.
	 */
	public void setSortByTitle(boolean orderByTitle) {
		this.sortByTitle = orderByTitle;
	}
	/**
	 * @return Returns the fETCH_SEARCH_RESULTS.
	 */
	public static String getFETCH_SEARCH_RESULTS() {
		return FETCH_SEARCH_RESULTS;
	}
	/**
	 * @return Returns the loc_countryiso3.
	 */
	public String getLoc_countryiso3() {
		return loc_countryiso3;
	}
	/**
	 * @param loc_countryiso3
	 *            The loc_countryiso3 to set.
	 */
	public void setLoc_countryiso3(String loc_countryiso3) {
		this.loc_countryiso3 = loc_countryiso3;
	}
	/**
	 * @return Returns the loc_countyId.
	 */
	public int getLoc_countyId() {
		return loc_countyId;
	}
	/**
	 * @param loc_countyId
	 *            The loc_countyId to set.
	 */
	public void setLoc_countyId(int loc_countyId) {
		this.loc_countyId = loc_countyId;
	}
	/**
	 * @return Returns the loc_cregionId.
	 */
	public int getLoc_cregionId() {
		return loc_cregionId;
	}
	/**
	 * @param loc_cregionId
	 *            The loc_cregionId to set.
	 */
	public void setLoc_cregionId(int loc_cregionId) {
		this.loc_cregionId = loc_cregionId;
	}
	/**
	 * @return Returns the loc_regionId.
	 */
	public int getLoc_regionId() {
		return loc_regionId;
	}
	/**
	 * @param loc_regionId
	 *            The loc_regionId to set.
	 */
	public void setLoc_regionId(int loc_regionId) {
		this.loc_regionId = loc_regionId;
	}
	/**
	 * @return Returns the loc_townId.
	 */
	public int getLoc_townId() {
		return loc_townId;
	}
	/**
	 * @param loc_townId
	 *            The loc_townId to set.
	 */
	public void setLoc_townId(int loc_townId) {
		this.loc_townId = loc_townId;
	}
	/**
	 * @return Returns the loc_villageId.
	 */
	public int getLoc_villageId() {
		return loc_villageId;
	}
	/**
	 * @param loc_villageId
	 *            The loc_villageId to set.
	 */
	public void setLoc_villageId(int loc_villageId) {
		this.loc_villageId = loc_villageId;
	}
}